#ifdef __cplusplus  //C++中dll导出函数的方法
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif

#include "udf.h"

static real gauge=0;

extern double rhomass_Tp(double x,double y);
extern double visc_Tp(double x,double y);
extern double tcond_Tp(double x,double y);
extern double cpmass_Tp(double x,double y);
extern double hmass_Tp(double x,double y);
extern double umass_Tp(double x,double y);
extern double smass_Tp(double x,double y);
extern double speed_sound_Tp(double x,double y);
extern double T_phmass(double x,double y);
extern double T_psmass(double x,double y);
extern double p_hsmass(double x,double y);
extern double T_hsmass(double x,double y);

DEFINE_PROPERTY(vapor_density,c,t)
{
    real den01,temp_a,pres_b;
	temp_a=C_T(c,t);
    pres_b=C_P(c,t)+gauge;
    den01=rhomass_Tp(temp_a,pres_b);
	if(den01<0.25)den01=0.25;
	if(den01>10000)den01=10000;
    return den01;
}
 
DEFINE_PROPERTY(vapor_viscosity,c,t)
{
    real visc1,temp_a,pres_b;
	temp_a=C_T(c,t);
    pres_b=C_P(c,t)+gauge;
    visc1=visc_Tp(temp_a,pres_b);
	if(visc1<1.0e-7)visc1=1.0e-7;
	if(visc1>1.0e-3)visc1=1.0e-3;
    return visc1;
}
 
DEFINE_PROPERTY(vapor_thermalConduct,c,t)
{
    real lamuda,temp_a,pres_b;
	temp_a=C_T(c,t);
    pres_b=C_P(c,t)+gauge;
    lamuda=tcond_Tp(temp_a,pres_b);
	if(lamuda<0.001)lamuda=0.001;
	if(lamuda>10.0)lamuda=10.0;	
	return lamuda;
}
 
DEFINE_SPECIFIC_HEAT(vapor_specificHeat,Tt,Tref,enthalpy,yi)
{
    real cp_a1,pres_ab;
	Domain *domain=Get_Domain(1);
    Thread *t;
    cell_t c;
	
	cp_a1=2000.0;
	
	thread_loop_c(t,domain)
    {
        begin_c_loop(c,t)
        {
			pres_ab=C_P(c,t)+gauge;
			Tt=C_T(c,t);
			cp_a1=cpmass_Tp(Tt,pres_ab);
			*enthalpy=cp_a1*(Tt-Tref);
			if(cp_a1<1.0)cp_a1=1.0;
			if(cp_a1>1.0e5)cp_a1=1.0e5;	
			return cp_a1;
        }
		end_c_loop(c,t)
    }
}

DEFINE_ON_DEMAND(testIF97)
{
    real T=500;
    real p=11e6; 
#if RP_HOST
    Message("water Properties(T=500K,p=11MPa)\n");
    Message("-----------------------------\n");
    Message("rho:%g\n",rhomass_Tp(T,p));
    Message("cp:%g\n",cpmass_Tp(T,p));
    Message("viscosity:%g\n",visc_Tp(T,p));
    Message("Thermal Conductivity:%g\n",tcond_Tp(T,p));
#endif
}